<?php
class Rooms {
    public function check_room($building,$number) // sprawdza, czy dana sala zostałą już dodana
    {
		$database = Database::getInstance();
		$check_query = $database->dbh->prepare("SELECT id FROM room WHERE building='{$building}' and number='{$number}'");
		$check_query->execute();
		if($check_query->rowCount() > 0){ 
			return 0; // znaleziono w bazie taką salę
		}else{
			return 1; // nie ma jeszcze takiej sali
		}
    }
	
	public function add_room($building,$number,$capacity) // dodaje salę do bazy
    {
		$database = Database::getInstance();
		$register_query = $database->dbh->prepare("INSERT INTO room (building,number,capacity) VALUES ('{$building}','{$number}','{$capacity}')");
		
		if($register_query->execute()){ 
			return 1; // zarejestrowano
		}else{
			return 0; // coś się nie udało
		}
    }
	
	public function get_rooms()
	{
		$database = Database::getInstance();
		$get_query = $database->dbh->prepare("SELECT building,number,capacity FROM room");
		$get_query->execute();
		$result = $get_query->fetchAll();
		foreach($result as $id => $room) {
			$roomData[$id]['building'] = $room['building'];
			$roomData[$id]['number'] = $room['number'];
			$roomData[$id]['capacity'] = $room['capacity'];
        }
		return $roomData;
	}
} 

?>